#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],fa[maxn];
vector<LL>g[maxn];
void dfs(LL u,LL fat){
     fa[u]=fat;
     for(LL i=0;i<g[u].size();i++){
         LL v=g[u][i];
         if(v==fat) continue;
         dfs(v,u);
     }
}
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL n;cin>>n;
   for(LL i=1;i<=n;i++) cin>>a[i];
   for(LL i=1;i<n;i++){
       LL u,v;cin>>u>>v;
       g[u].push_back(v);g[v].push_back(u);
   }
   dfs(1,0);
   fa[0]=0;
   LL ans=0;
   for(LL j=1;j<=n;j++){
       LL gcd=0;
       gcd=__gcd(a[j],gcd);
       ans=(ans%mod+gcd%mod)%mod;
       LL i=j;
       while(fa[i]!=0&&i){
          i=fa[i];
          gcd=__gcd(gcd,a[i]);
          ans=(ans%mod+gcd%mod)%mod;
       }
   }
   cout<<ans%mod<<"\n";
   return 0;
}
